<?php

namespace backend\models;

use Yii;
use yii\base\Model;

/**
 * @author  shuang
 * @date    2016-10-11 15:38:29
 * @version V1.0
 * @desc    
 */
class TaskparamsForm extends Model {

    public $topcount; //任务置顶数量
    public $reflash_price; // 刷新价格(单次)
    public $upgrade_amount; //升级余额条件
    public $credit_amount; //充值金额
    public $single_task_votes; //单次任务20票起
    public $sys_invite_code; //系统邀请码
    public $more_meet_limit; //可以操作单项任务多次限制
    public $merchants_url; //商户网址
    public $operate_task_url; //任务网址
    public $rebate_drawal; //返利提现设置
    public $rebate_amount; //可提现金额

    /**
     * @inheritdoc
     */

    public function rules() {
        return [
            [['topcount', 'reflash_price'], 'required'],
            [['sys_invite_code','merchants_url','operate_task_url'], 'string'],
            [['topcount', 'reflash_price'], 'number', 'max' => 100],
            [['upgrade_amount', 'credit_amount', 'single_task_votes','more_meet_limit','rebate_drawal','rebate_amount'], 'number'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels() {
        return [
            'topcount' => '任务置顶数量',
            'reflash_price' => '刷新价格(单次)',
            "upgrade_amount" => "升级余额条件",
            'credit_amount' => "充值金额",
            'single_task_votes' => "单次任务票起",
            'sys_invite_code' => "系统邀请码",
            'more_meet_limit'=>"单项多次任务限制",
            'merchants_url'=>"商户网址",
            'operate_task_url'=>"任务网址",
            'rebate_drawal'=>"返利提现设置",
            'rebate_amount'=>"可提现金额"
        ];
    }

    public function updateParams() {
        if ($this->validate()) {
            $string = "<?php\n return \n [";
            foreach ($this->attributes as $attributes => $value) {
                $string .="'$attributes'=>'$value',";
            }
            $string .= "];";
            return file_put_contents(Yii::getAlias('@common/config/params-local.php'), $string);
        } else {
            return ["errors" => $this->getErrors(), "model" => $this];
        }
    }

}
